/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text, Table, TableBody, TableRow, CCell, TableHead, useTheme,
} from "customize-easy-ui-component";
import {DirectLink, } from "../../../routing/Link";
import {ReportViewProps, } from "../../common/base";
import {末尾链接,} from "../../common/rarelyVary";
import {填写须知} from "../../escalator/rarelyVary";
import {setupItemAreaRoute} from "./orcIspConfig";
import queryString from "query-string";
import {config观测数据, config观测数据2, config设备概况} from "./orcBase";
import {俩列检验设备概况} from "../../park/views";
import {首页概况ElevJj} from "../../elevator/viewFirst";
import {useFormatOmniLikeSafW} from "../hook/useFormatOmniLikeSafW";
import {测量记录两半} from "../walk/repView";
import {运行速度偏差} from "./SpeedBias";
import {扶手带速度偏差} from "./HandrailBias";
import {运行振动评价表} from "./VibrationEval";
import {UnqualifiedIspTableEvalSplitO, } from "../general";
import {useItemsMapEval} from "../config";
import {ConclusionVw} from "./Conclusion";
import {floatInterception} from "../../../common/tool";
import {useCalcEvalTotalScore} from "../hook/useCalcEvalTotalScore";
import {常用现场条件} from "../../park/viewX";
import {tItems现场} from "./Regular.O-1";

//格式化版的原始记录 和 正式报告：目的功能定位叉开。前者只是用于打印目的。后者不仅要打印还要导航编辑器区块。打印A4竖版的布局;
export const FormatOriginal: React.FunctionComponent<ReportViewProps> = ({
    repId,   source: orc,  verId,rep,
}) => {
    const theme= useTheme();
    const qs= queryString.parse(window.location.search);
    const printing =qs && !!qs.print;
    const impressionismAs =React.useMemo(() => {
        return setupItemAreaRoute({rep,orc, theme});
    }, [rep,orc?._Oitems, theme]);
    const {renderIspContent} =useFormatOmniLikeSafW({model: rep?.modeltype, repNo: repId!, ver: verId, itRes:orc,ItemArs:impressionismAs?.Item, });
    const [mapNoTag]=useItemsMapEval({ ItemArs:impressionismAs?.Item, });
    const evalTotalScore=floatInterception(useCalcEvalTotalScore({itRes:orc, ItemArs:impressionismAs?.Item}),2);
  return (
    <React.Fragment>
        <div css={{"@media not print": {marginTop: '1rem', marginBottom: '1rem'}}}>
            <div css={{
                textAlign: "center",
                "& > div": {
                    marginLeft: "auto",
                    marginRight: "auto"
                },
                "@media (min-width:690px),print and (min-width:538px)": {
                    display: "flex",
                    justifyContent: "space-between",
                    flexWrap: 'wrap',
                    "& > div": {
                        margin: theme.spaces.sm,
                    }
                },
                flexDirection: 'row-reverse',
            }}>
                <Text variant="h5" css={{textDecoration: 'underline'}}>FJJ/QB-1002-1-2023</Text>
            </div>
            <Text variant="h3" css={{
                textAlign: 'center',
                "@media (min-width:690px),print and (min-width:538px)": {
                    fontSize: theme.fontSizes[5],
                },
                marginTop: '2rem',
            }}>
                电梯定期检验原始记录
            </Text>
            <Text variant="h5" css={{textAlign: 'center',}}>（杂物电梯）</Text>
            <Text variant="h5" css={{textAlign: 'center',}}>
                （适于： 格式化版记录 待续...）
            </Text>
            <div css={{"@media print": {height: '18mm'}}}>
            </div>
            <div css={{"@media print": {minHeight: '-webkit-fill-available',}}}>
                {首页概况ElevJj({theme, orc, original: true, rep})}
            </div>
            <div css={{"@media print": {height: '20mm'}}}>
            </div>
            <div css={{
                textAlign: 'center',
                "@media print": {
                    pageBreakAfter: 'always',
                    pageBreakInside: 'avoid'
                }
            }}>
                <Text variant="h4" css={{
                    textAlign: 'center',
                }}>福建省特种设备检验研究院编制</Text>
            </div>
            {填写须知}
            <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/Survey`}>
                <Text variant="h4" css={{"@media print": {pageBreakBefore: 'always',},
                }}>一、设备概况</Text>
            </DirectLink>
            <Table fixed={["16%", "34%", "16%", "34%"]} css={{borderCollapse: 'collapse'}} tight miniw={800}>
                <TableBody>
                    {俩列检验设备概况({orc, rep, repId: repId!, verId, config: config设备概况})}
                </TableBody>
            </Table>
            <div css={{"@media print": {pageBreakInside: 'avoid'}}}>
                <Text variant="h4" css={{marginTop: '1rem',}}>二、评估依据</Text>
                1、科技成果：《基于模糊层次分析法的扶梯安全风险评估研究》（FJQI2013070）<br/>
                2、DB35/T 1936-2020《自动扶梯和自动人行道运行振动测量和评价》
            </div>
            <div css={{"@media print": {paddingBottom: '7rem', pageBreakInside: 'avoid'}}}>
                <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/Instrument`}>
                    <Text variant="h4" css={{
                        marginTop: '1rem',
                    }}>三、主要检测仪器</Text>
                </DirectLink>
            </div>
            <Table fixed={["%", "24%", "22%", "8%", "8%"]}
                        css={{borderCollapse: 'collapse', "@media print": {marginTop: '-7rem'}}} tight miniw={800}>
                    <TableHead>
                        <TableRow>
                            <CCell rowSpan={2}>仪器设备名称</CCell>
                            <CCell rowSpan={2}>型号规格</CCell>
                            <CCell rowSpan={2}>仪器设备编号</CCell>
                            <CCell colSpan={2}>性能状态</CCell>
                        </TableRow>
                        <TableRow>
                            <CCell>开机后</CCell>
                            <CCell>关机前</CCell>
                        </TableRow>
                    </TableHead>
                    <TableBody>
                        <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/Instrument`}>
                            {orc.仪器表?.map((o: any, i: React.Key) => {
                                return (
                                    <TableRow key={i}>
                                        <CCell>{o.n}</CCell>
                                        <CCell>{o.t}</CCell>
                                        <CCell css={{wordBreak: 'break-all'}}>{o.i}</CCell>
                                        <CCell>{o.o}</CCell>
                                        <CCell css={{wordBreak: 'break-all'}}>{o.f}</CCell>
                                    </TableRow>
                                );
                            })}
                        </DirectLink>
                    </TableBody>
                </Table>
                <Text>
                    注：1、性能状态一栏中用“√”表示正常，用“×”表示不正常。
                    <Text css={{display: 'flex', marginLeft: '2rem'}}>
                        2、若仪器设备性能状态不正常，应更换为性能状态正常的仪器设备，并填写在预留栏中。<br/>
                        3、新增使用的仪器设备应填写在预留栏中。<br/>
                        4、未使用的仪器设备可不填写。
                    </Text>
                </Text>
                <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/ALL`}>
                    <Text variant="h4" css={{"@media print": {pageBreakBefore: 'always',},
                    }}>四、 评估原始记录表</Text>
                </DirectLink>
                <Table fixed={["2%", "4%", "6%", "3%", "%", "4%", "4%", "4%", "4%", "3%", "3%", "8%"]}
                       css={{borderCollapse: 'collapse'}} tight miniw={800}>
                    <TableHead>
                        <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/ALL`}>
                            <TableRow>
                                <CCell><Text css={{fontSize: '0.8rem'}}>序号</Text></CCell>
                                <CCell colSpan={2}>检测项目</CCell>
                                <CCell><Text css={{fontSize: '0.8rem'}}>编号</Text></CCell>
                                <CCell>评估内容与要求</CCell>
                                <CCell><Text css={{fontSize: '0.7rem'}}>检测结果</Text></CCell>
                                <CCell><Text css={{fontSize: '0.7rem'}}>严重程度</Text></CCell>
                                <CCell><Text css={{fontSize: '0.7rem'}}>风险频率</Text></CCell>
                                <CCell><Text css={{fontSize: '0.7rem'}}>风险类别</Text></CCell>
                                <CCell>权重</CCell><CCell>得分</CCell>
                                <CCell><Text css={{fontSize: '0.7rem'}}>确认方式或存在问题</Text></CCell>
                            </TableRow>
                        </DirectLink>
                    </TableHead>
                    <TableBody>
                        {renderIspContent}
                    </TableBody>
                </Table>
                <Text>
                    备注：项目编号后A表示必须整改项目、B表示现行安全技术规范或标准新要求的项目，无标注的表示建议整改项目，标有※的项目为应当遵循“水桶短板理论”的评估项目。
                </Text><br/>
            <ConclusionVw orc={orc} rep={rep} evalTotalScore={evalTotalScore!} label={'五、评估结论'}/>
            <Table fixed={ ["8.2%", "%", "4.8%", "13%"] } css={{borderCollapse: 'collapse'}} tight miniw={800}>
                <TableBody>
                    <TableRow >
                        <CCell>评估人员</CCell><CCell>{orc.检验人IDs}</CCell><CCell>日期</CCell><CCell>{orc.编制日期}</CCell>
                    </TableRow>
                    <TableRow >
                        <CCell>校核</CCell><CCell></CCell><CCell>日期</CCell><CCell>2024-12-31</CCell>
                    </TableRow>
                </TableBody>
            </Table>
            <UnqualifiedIspTableEvalSplitO rep={rep} orc={orc} mapNoTag={mapNoTag} printing={printing}/>

            {测量记录两半({
                orc, rep, config1: config观测数据, config2: config观测数据2, label: '六、观测数据',
                fixed: ["2%", "5%", "0", "6%", "%", "13%", "4.1%", "8%", "7%", "5%"], children: ' '
            })}
            {运行速度偏差({orc, rep, label: '附录A 空载梯级（踏板、胶带）运行速度与名义速度偏差（简易方法）'})}
            {扶手带速度偏差({orc, rep, label: '附录B 空载梯级（踏板、胶带）和扶手带运行速度偏差（简易方法）'})}
            {运行振动评价表({orc, rep, label: '附录C 自动扶梯和自动人行道运行振动评价表'})}

            {常用现场条件({orc, rep, config: tItems现场, dcln: 3, jyt: '检测', children: ' ', label: '附录D 现场检测条件确认'})}
        </div>
        {末尾链接({template: rep?.modeltype, verId, repId: repId || ''})}
    </React.Fragment>
);
}
